package com.lcf.app.quartz.config;

import com.lcf.app.quartz.job.MyJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ChenFei
 * @date 2022/1/22
 */
@Configuration
public class QuartzConfig {

    private static final String JOB_GROUP = "JOB_GROUP";
    private static final String TRIGGER_GROUP = "TRIGGER_GROUP";

    @Bean
    public JobDetail myJobDetail() {
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .withIdentity("myJobDetail", JOB_GROUP)
                .usingJobData("jobKey", "jobData")
                .storeDurably()
                .build();
        return jobDetail;
    }

    @Bean
    public Trigger myTrigger() {
        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(myJobDetail())
                .withIdentity("myTrigger", TRIGGER_GROUP)
                .usingJobData("triggerKey", "triggerData")
                .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                .build();
        return trigger;
    }

}
